<?php declare(strict_types=1);

namespace App\Console\Command;

use App\Helper\RedisConst;
use App\Model\Logic\FormatDataLogic;
use App\Model\Logic\PostEsLogic;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Console\Annotation\Mapping\Command;
use Swoft\Console\Annotation\Mapping\CommandMapping;
use Swoft\Console\Exception\ConsoleErrorException;
use Swoft\Console\Helper\Show;
use Swoft\Console\Input\Input;
use Swoft\Redis\Pool;

/**
 * Class DemoCommand
 *
 * @Command()
 */
class DemoCommand
{

    /**
     * @Inject("redis1.pool")
     * @var Pool
     */
    private $redis;

    /**
     * @Inject()
     * @var FormatDataLogic
     */
    private $format;

    /**
     * @CommandMapping()
     * @param Input $input
     */
    public function test(Input $input): void
    {
        Show::prettyJSON([
            'args' => $input->getArgs(),
            'opts' => $input->getOptions(),
        ]);
    }

    /**
     * @CommandMapping("err")
     * @throws ConsoleErrorException
     */
    public function coError(): void
    {
        ConsoleErrorException::throw('this is an error message');
    }

    /**
     * @CommandMapping("code")
     */
    public function code()
    {
        $key = RedisConst::MEMBER . '987';
        $data = $this->redis->dump($key);
        echo $k = 'a'.$key."store";
        $res = $this->redis->restore($k, 600, $data);
        var_dump($res);
    }



}
